package com.turbo.cloud.ums.web.webservice;

import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.validated.InsertValidated;
import com.turbo.cloud.core.validated.UpdateValidated;
import com.turbo.cloud.ums.web.logic.DeptLogic;
import com.turbo.cloud.ums.web.model.dept.UmsDeptDO;
import com.turbo.cloud.ums.web.model.dept.UmsDeptVO;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2022-10-11
 */
@RequiredArgsConstructor
@RestController
public class UmsDeptController {

    final DeptLogic deptLogic;

    /**
     * 查询部门列表
     *
     * @return
     */
    @PostMapping(name = "查询部门列表", value = "/webservice/dept/queryDeptList")
    public Result<List<UmsDeptVO>> queryDeptList() {
        List<UmsDeptVO> result = deptLogic.queryDeptList();
        return R.result(result);
    }

    /**
     * 查询部门树列表
     *
     * @return
     */
    @PostMapping(name = "查询部门树列表", value = "/webservice/dept/queryDeptTreeList")
    public Result<List<UmsDeptVO>> queryDeptTreeList() {
        List<UmsDeptVO> result = deptLogic.queryDeptTreeList();
        return R.result(result);
    }

    /**
     * 新增部门
     *
     * @param umsDeptDO 实体
     * @return
     */
    @PostMapping(name = "新增部门", value = "/webservice/dept/createDept")
    public Result<Boolean> createDept(@RequestBody @Validated(InsertValidated.class) UmsDeptDO umsDeptDO) {
        boolean result = deptLogic.createDept(umsDeptDO);
        return R.result(result);
    }

    /**
     * 修改部门
     *
     * @param umsDeptDO 实体
     * @return
     */
    @PostMapping(name = "修改部门", value = "/webservice/dept/modifyDept")
    public Result<Boolean> modifyDept(@RequestBody @Validated(UpdateValidated.class) UmsDeptDO umsDeptDO) {
        boolean result = deptLogic.modifyDept(umsDeptDO);
        return R.result(result);
    }

    /**
     * 删除部门
     *
     * @param id 部门ID
     * @return
     */
    @GetMapping(name = "删除部门", value = "/webservice/dept/removeDeptById")
    public Result<Boolean> removeDeptById(@NotBlank(message = "部门ID不能为空") String id) {
        boolean result = deptLogic.removeDeptById(id);
        return R.result(result);
    }
}
